/*
 * @lc app=leetcode.cn id=46 lang=javascript
 *
 * [46] 全排列
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function (nums) {
    const res = []
    const used = {}

    const dfs = (path) => {
        if (path.length === nums.length) {
            res.push(path.slice())
            return
        }
        for (let i of nums) {
            if (used[i]) continue
            path.push(i)
            used[i] = true
            dfs(path)
            used[i] = false
            path.pop()
        }
    }
    dfs([])


    return res
};
// @lc code=end

